<template>
  <div class="company-list-1">
    <div class="header">
      <div class="prefix"></div>
      <div class="header-title">任务类型分布</div>
    </div>
    <div class="content">
      <div style="width: 100%; height: 200px">
        <MyEchart :option="dataSource"></MyEchart>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted, watchEffect } from 'vue'
import MyEchart from '@/components/echarts/MyCharts2.vue'

const props = defineProps({
  info: {
    type: Object,
    default: () => ({})
  }
})

const dataSource = ref()

watchEffect(() => {
  const taskType = []
  if (props.info && props.info.length) {
    props.info.forEach((item) => {
      taskType.push({
        name: item.taskType,
        value: item.count
      })
    })
  }

  dataSource.value = {
    tooltip: {
      trigger: 'item'
    },
    series: [
      // 画外部描述的饼图
      {
        type: 'pie',
        radius: '65%',
        center: ['50%', '50%'],
        data: taskType,
        label: {
          show: true,
          position: 'outside',
          color: '#fff',
          fontSize: 16
        },
        labelLine: {
          show: true
        }
      },
      // 画内部百分比的饼图
      {
        type: 'pie',
        data: taskType,
        label: {
          show: true,
          position: 'inside',
          formatter: `{d}%`
        }
      }
    ]
  }
})
</script>

<style scoped lang="scss">
@import '@/assets/table.css';

.company-list-1 {
  padding: 10px;
  width: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  font-size: 16px;

  .header {
    width: 350px;
    height: 50px;
    display: flex;
    align-items: center;
    padding-left: 20px;

    .prefix {
      width: 8px;
      height: 15px;
      background-color: #31a7ff;
    }

    .header-title {
      padding-left: 10px;
    }
  }

  .content {
    flex: 1;
    display: flex;
    justify-content: space-between;
    padding: 0 10px;
  }
}
</style>
